<?php

class Domena extends Zend_Db_Table {

    protected $_name = 'domeny';

    public function edycjaDomeny($id, $nazwa, $title, $description, $keywords, $styl) {
        $row = $this->fetchRow($this->select()
                                ->where('id=?', $id));
        if ($row) {
            $row->id = $id;
            $row->nazwa = $nazwa;
            $row->title = $title;
            $row->description = $description;
            $row->keywords = $keywords;
            $row->styl = $styl;
            $row->save();
            return TRUE;
        } else {
            throw new Zend_Exception('Nie można edytować domeny. Nie znaleziono rekordu!');
        }
    }

    public function usunDomena($id) {
        $row = $this->find($id)->current();
        if ($row) {
            $row->id = $id;
            $row->active = 0;
            $row->usun = 1;
            $row->save();
            return TRUE;
        } else {
            throw new Zend_Exception('Nie można usunąć domeny. Nie znaleziono rekordu!');
        }
    }

    public function getAll() {
        $select = $this->select()->where('usun=0');
        $select->order('active ASC');
        $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
        return $adapter;
    }

    public function getDomain($domena) {
        $row = $this->fetchRow($this->select()
                                ->where('nazwa LIKE ?', $domena));
        if ($row) {
            return $row;
        } else {
            return FALSE;
        }
    }

}
